<?php
class Preference extends MY_Controller{

	function __construct()
	{
		parent::__construct();
		if(!$this->admin || $this->admin->status !=1 ) redirect('login');
	}


	function index()
	{
		redirect('preference/administration');
	}

	/* Administration */
	function administration($action=NULL,$id=NULL)
	{
		$data['admins'] = admin::find('all');
		$data['title'] = $this->title('administration');
		$this->load->view('default/header',$data);
		if($action = 'edit' && $id !=NULL)
		{
			$this->authority->initialize($this->admin);
			if(can('read','Preference')){
			$data['admin'] = admin::find_by_id($id);
			$this->load->view('default/preference/admin_edit',$data);
			}else{
				$data['error_msg'] = "Your permission level is not enough.";
				$this->load->view('default/preference/administration',$data);
			}
		}else{
			$this->load->view('default/preference/administration');
		}
		$this->load->view('default/footer');

	}

	
	/* Themes */
	function theme($action=NULL,$id=NULL)
	{
		$data['title'] = $this->title('theme');
		$data['theme'] = $this->get_themes('./'.APPPATH.'views');
		$this->load->view('default/header',$data);
		$this->load->view('default/preference/theme');
		$this->load->view('default/footer');
	}
	
	function get_themes($url)
	{
		
		return $themes = directory_map($url,2,TRUE);
		
	}
}